package middlewares

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func AuthMiddleware(expectedAccount string, expectedPassword string) gin.HandlerFunc {
	return func(c *gin.Context) {
		account := c.Query("account")
		password := c.Query("password")

		if account == "" || password == "" {
			c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
				"error": "Missing required parameters",
			})
			return
		}

		if account != expectedAccount || password != expectedPassword {
			c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
				"error": "Invalid credentials",
			})
			return
		}

		c.Next()
	}
}
